package com.xcity.game.combat.skill.impl;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 尔虞我诈<br/>
 * 曹操不啰嗦！随机降低一个敌方目标{0=20#0}%攻击力，持续{1=2#0}回合
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90097 extends CombatSkill {

	public COMBAT_SKILL_90097(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit unit = action.target.getUnitRandomly();
		if (unit != null) {
			ActionEffect effect = action.addTarget(unit);
			unit = effect.getUnit(); // 修正目标
//			int damage = CombatUtils.calcCommonMagicDamage(action.unit, unit);
//			effect.effect(CombatAttributeType.HP, -damage);
			CombatUtils.calcMagicAttack(effect);
			// debuff
			action.addBuff(new BUFF(skill, unit));
		}
	}
	
	static class BUFF extends CombatBuff {
		int oldAttackPower;
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner, (int) skill.getParameter(1));
			active = true;
			int power = (int) owner.getAttackPower();
			oldAttackPower = power;
			power -= power * skill.getParameter(0) / GameStaticConfig.percentBase;
			owner.setAttributeValue(CombatAttributeType.ATTACK_POWER, power);
		}
		@Override
		public void roundEnd(Round round) {
			super.roundEnd(round);
			if (state == STATE_REMOVED) {
				owner.setAttributeValue(CombatAttributeType.ATTACK_POWER, oldAttackPower);
			}
		}
		@Override
		@JSONField(serialize = false)
		public boolean isDebuff() {
			return true;
		}
	}

}
